//
//  TopicDetailHeaderView.m
//  Findif
//
//  Created by Mac on 2019/3/18.
//  Copyright © 2019年 Cicel Chen. All rights reserved.
//

#import "TopicDetailHeaderView.h"

@interface TopicDetailHeaderView ()

@property (nonatomic, weak)UIView * backView;
@property (nonatomic, weak)UIImageView * backImageView;
@property (nonatomic, weak)UIImageView * topicImageView;
@property (nonatomic, weak)UILabel * titleLabel;
@property (nonatomic, weak)UILabel * countLabel;

@end

@implementation TopicDetailHeaderView

- (void)setModel:(TopicModel *)model{
    
    _model = model;
    
    NSString * iconStr = [NSString stringWithFormat:@"%@%@",BASEURLSTR,model.topic_img];
    NSURL * iconUrl = [NSURL URLWithString:iconStr];
    [self.backImageView sd_setImageWithURL:iconUrl];
    
    self.titleLabel.text = [NSString stringWithFormat:@"#%@#",model.topic_title];
    self.countLabel.text = [NSString stringWithFormat:@"%@人讨论",model.comment_count];
}


- (void)setDict:(NSDictionary *)dict{
    
    _dict = dict;
    
    NSString * iconStr = [NSString stringWithFormat:@"%@%@",BASEURLSTR,dict[@"topic_img"]];
    NSURL * iconUrl = [NSURL URLWithString:iconStr];
    [self.backImageView sd_setImageWithURL:iconUrl];
    
    self.titleLabel.text = [NSString stringWithFormat:@"#%@#",dict[@"topic_title"]];
    self.countLabel.text = [NSString stringWithFormat:@"%@人讨论",dict[@"comment_count"]];
}

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithReuseIdentifier:reuseIdentifier]) {
        
        [self setupUI];
    }
    return self;
}

- (void)setupUI{
    
    UIImageView * backImageView = [UIImageView new];
    
    backImageView.contentMode = UIViewContentModeScaleAspectFill;
    backImageView.layer.cornerRadius = 5 * SCREENH6;
    backImageView.layer.masksToBounds = YES;
    
    self.backImageView = backImageView;
    
    [self addSubview:self.backImageView];
    
    UIView * backView = [[UIView alloc] init];
    
    backView.backgroundColor = ZRBlackColor;
    backView.alpha = 0.4;
    backView.layer.cornerRadius = 5 * SCREENH6;
    backView.layer.masksToBounds = YES;
    
    self.backView = backView;
    
    [self.backImageView addSubview:self.backView];

    
    UIImageView * topicImageView = [UIImageView new];
    
    topicImageView.image = [UIImage imageNamed:@"话题卡"];
    
    self.topicImageView = topicImageView;
    
    [self.backImageView addSubview:self.topicImageView];
    
    
    UILabel * titleLabel = [UILabel new];
    
    titleLabel.text = @"#世界那么多大，我想去看看#";
    titleLabel.textColor = ZRWhiteColor;
    titleLabel.font = [UIFont boldSystemFontOfSize:18 * SCREENH6];
    
    self.titleLabel = titleLabel;
    
    [self.backImageView addSubview:self.titleLabel];
    
    
    UILabel * countLabel = [UILabel new];
    
    countLabel.text = @"45人讨论";
    countLabel.textColor = [UIColor lightGrayColor];
    countLabel.font = [UIFont systemFontOfSize:13 * SCREENH6];
    
    self.countLabel = countLabel;
    
    [self.backImageView addSubview:self.countLabel];
    
}


- (void)layoutSubviews{
    
    [self.backImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.centerX.mas_equalTo(self);
        make.width.mas_equalTo(345 * SCREENH6);
        make.height.mas_equalTo(80 * SCREENH6);
    }];
    
    [self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.top.bottom.mas_equalTo(self.backImageView);
    }];
    
    [self.topicImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(20 * SCREENH6);
        make.centerY.mas_equalTo(self.backImageView);
        make.width.height.mas_equalTo(40 * SCREENH6);
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.topicImageView.mas_trailing).offset(10 * SCREENH6);
        make.trailing.mas_equalTo(self.backImageView).offset(-10 * SCREENH6);
        make.top.mas_equalTo(self.topicImageView);
    }];
    
    [self.countLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.topicImageView.mas_bottom);
        make.leading.mas_equalTo(self.titleLabel);
    }];
}


@end
